package com.seashop.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.seashop.response.ResponseBase;
import com.seashop.request.GoogleTransRequestParam;
import com.seashop.service.ITranslateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author moredln
 * @desc 翻译控制器
 * @date 2020-08-11 11:26
 */
@RestController
@RequestMapping("/google")
@Api(tags = "谷歌翻译")
public class TranslateController {

    @Autowired
    private ITranslateService translateService;

    @PostMapping("/batchTrans")
    @ApiOperation(value = "批量翻译")
    public ResponseBase batchTrans(@RequestBody GoogleTransRequestParam param) {
        if (CollectionUtils.isEmpty(param.getTexts())) {
            return ResponseBase.success();
        }
        List<String> result = translateService.batchTrans(param);
        return ResponseBase.success(result);
    }

    @GetMapping("/trans")
    @ApiOperation(value = "单条翻译")
    public String trans(String text, String fromLanguageType, String toLanguageType) {
        return translateService.trans(text, fromLanguageType, toLanguageType);
    }
}
